<?php
namespace app\admin\controller;
use \think\View;
use think\Input;
use think\Controller;
use think\Db;
use think\Session;

class Login extends Admin
{ 

    public function login(){
    
  
      return $this->view->fetch('');

    }

    public function login_index()
    {
       //获取输入数据
       $login     = input('post.');
       //用户账号
       $username  = $login['username'];
       //用户密码
       $password  = $login['password'];

       $pass = MD5(MD5($password).'*SWER5%');

       //时间
       $new = date('Y-m-d H:i:s');
       //登录
       $result = Db::table('user')->where(['username' => ['=', $username], 'password' => ['=', $pass]])->find();
       //最后一次登录时间

       $time =[
       'login_time' =>$new
       ];
       Db::table('user')->where('username', $username)->update($time);
       if (!$result == null)
       {
            // $_SESSION["id"] = $result['id'];
            // $_SESSION["username"] = $result['username'];

            Session::set('id',$result['id']);
            Session::set('username',$result['username']);

           return $this->success('登录成功', url('active/index'));
       }
       else{
        	return $this->error('登陆失败');
       }
      
    }

    public function login_out()
    {
    	 Session::set('id','');
       Session::set('username','');
    	$this->success('退出成功', url('login/login'));
    }

}

